package com.hustzp.com.xichuangzhu.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.avos.avoscloud.AVUser;
import com.hustzp.com.xichuangzhu.R;
import com.hustzp.com.xichuangzhu.login.LoginActivity;
import com.hustzp.com.xichuangzhu.login.ReceiveSmsCodeActivity;
import com.hustzp.com.xichuangzhu.utils.Constant;

/**
 * Created by Administrator on 2016/6/5.
 */
public class ChangePhonePwdActivity extends MyBaseActivity {

    private TextView phoneNum;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_phone_pwd);

        initToolbar();
        initViews();
    }

    private void initToolbar() {
        TextView navTxt = (TextView) findViewById(R.id.tv_nav_txt);
        navTxt.setText(getString(R.string.setting));
        TextView appTitle = (TextView) findViewById(R.id.tv_title_txt);
        appTitle.setText(getString(R.string.account_and_passwd));
    }

    private void initViews() {
        phoneNum = (TextView) findViewById(R.id.tv_phone_num);
        phoneNum.setText(AVUser.getCurrentUser().getMobilePhoneNumber());
    }

    public void clickView(View view) {
        switch (view.getId()) {
            case R.id.my_phone_btn:
                Intent intent = new Intent(ChangePhonePwdActivity.this, ReceiveSmsCodeActivity.class);
                intent.setAction(Constant.INTENT_ACTION_CHGPHONE);
                startActivity(intent);
//                startActivityForResult(new Intent(ChangePhonePwdActivity.this, ChangePhoneNoActivity.class), Constant.REQ_CODE_CHANGE_PHONE);
                break;
            case R.id.my_pwd_btn:
                startActivityForResult(new Intent(ChangePhonePwdActivity.this, ChangePasswordActivity.class), Constant.REQ_CODE_CHANGE_PASWD);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if ((requestCode == Constant.REQ_CODE_CHANGE_PHONE || requestCode == Constant.REQ_CODE_CHANGE_PASWD) && resultCode == RESULT_OK) {
            AVUser.logOut();
            startActivity(new Intent(ChangePhonePwdActivity.this, LoginActivity.class));
            finish();
        }
    }
}
